$(function () {
    var active = 0;
    var slideNun = $(".slideshow li").length;
    $(".btn-prev").click(function () {
        prev();
    })
    $(".btn-next").click(function () {
        next();
    })
    function prev() {
        active--;
        active = active == -1 ? slideNun - 1 : active;
        $(".slideshow>li").eq(active).fadeIn().siblings().fadeOut();
        $(".pagination>li").eq(active).addClass("active").siblings().removeClass("active");
    }
    function next() {
        active++;
        active = active == slideNun ? 0 : active;
        $(".slideshow>li").eq(active).fadeIn().siblings().fadeOut();
        $(".pagination>li").eq(active).addClass("active").siblings().removeClass("active");
    }

    var timer = setInterval(next, 1000);
    $(".banner-container").hover(function () {
        clearInterval(timer);
    }, function () {
        timer = setInterval(next, 1000);
    })

    for (var i = 0; i < slideNun; i++) {
        $(".pagination").append("<li></li>");
    }
    $(".pagination>li").eq(active).addClass("active");
    $(".pagination>li").on("click", function () {
        active = $(this).index()
        $(".slideshow>li").eq(active).fadeIn().siblings().fadeOut();
        $(this).addClass("active").siblings().removeClass("active");
    })
})

$(function () {
    var current = 0;// 已经经过li的个数
    var remainder = $("#section-shangou .goods-list li").length % 4;
    var surplus = $("#section-shangou .goods-list li").length - 4;
    $(".next").click(function () {
        current += 4;
        surplus -= 4; // 剩余未li的个数
        if (surplus >= remainder) {
            $("ul").animate({ left: -current * 248 });
        }
        else {
            $("ul").animate({ left: -(current - 4 + remainder) * 248 });
            current -= 4 - remainder;
            // console.log(current);
            $(this).addClass("disabled");
            surplus += 4 - remainder;
        }
        if (current > 0) {
            $(".prev").removeClass("disabled");
        }
        console.log(current, surplus);
    })
    $(".prev").click(function () {
        if (surplus == 0) {
            $(".next").removeClass("disabled");
        }
        if (current == 4) {
            $(".prev").addClass("disabled");
        }
        if (surplus >= remainder) {
            if (current !== 0) {
                $("ul").animate({ left: -(current - 4) * 248 });
                current -= 4;
                console.log(current);
                surplus += 4;
            }
        } else {
            surplus += remainder;
            $("ul").animate({ left: -(current - remainder) * 248 });
            current -= remainder;
            console.log(current);
        }
        console.log(surplus);
    })
});

$(function () {
    var starttime = Date.parse(new Date('2019/10/24')) + 24 * 60 * 60 * 1000; //8月1号15点
    setInterval(function () {
        var nowtime = Date.parse(new Date());
        var time = starttime - nowtime;
        var day = parseInt(time / 1000 / 60 / 60 / 24);
        var hour = parseInt(time / 1000 / 60 / 60 % 24);
        var minute = parseInt(time / 1000 / 60 % 60);
        var seconds = parseInt(time / 1000 % 60);

        $('.day').html(day)
        $('.hour').html(hour)
        $('.minute').html(minute)
        $('.seconds').html(seconds)


    }, 1000);
})

$(function () {
    $(window).scroll(function () {
        console.log(
            $(".section-jiadian").offset().top,
            $(document).scrollTop() //  被卷去的头部 scrollTop()
        );
        if ($(document).scrollTop() > $(".section-jiadian").offset().top) {
            $(".back-to-top").css("visibility", "visible");
        } else {
            $(".back-to-top").css("visibility", "hidden");
        }
    })
    $(".back-to-top").click(function () {
        $("html,body").animate({ scrollTop: 0 }, 200)
        console.log();
    })
})